package game.display;

import java.awt.Graphics;
import java.awt.Image;

import game.menu.Drawable;

/** Creates a moving star in the background
 * 
 * @author DMEComputer
 *
 */

public class Star implements Drawable
{
	private double dx;
	private double dy;
	private double x;
	private double y;
	
	private Animation star;
	
	/** Constructs the star x and y coordinates
	 * 
	 * @param x sets the x-coordinate
	 * @param y sets the y-coordinate
	 * @param dx sets the change in the x-coordinate from the original x-coordinate
	 * @param dy sets the change in the y-coordinate from the original y-coordinate
	 */
	
	public Star(double x, double y, double dx, double dy)
	{
		this.dx = dx;
		this.dy = dy;
		this.x = x;
		this.y = y;
		this.star = Images.STAR.image();
	}
	
	/** updates the position of the asteroid
	 * 
	 */
	
	public void update()
	{
		x += dx;
		y += dy;
		if (x + 64 < 0)
		{
			x = Background.getWidth();
			dx = (1 - 2*Math.random());
		}
		if (x > Background.getWidth())
		{
			x = -64;
			dx = (1 - 2*Math.random());
		}
		if (y + 64 < 0){
			y = Background.getHeight();
			dy =(1 - 2*Math.random());
		}
		if (y > Background.getHeight())
		{
			y = -64;
			dy = (1 - 2*Math.random());
		}
	}
	
	/** Draws the asteroid onto the background
	 * 
	 */

	@Override
	public void draw(Graphics g) 
	{
		g.drawImage(star.getImage(), (int)x, (int)y, null);
	}

}
